/**
 * 
 */
package fr.ants.view.component;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

import fr.ants.controller.listener.SliderPanelListener;

/**
 * This panel contain the element to have a slider, title and label.
 **/
public class SliderPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5788758291327838006L;
	/**
	 * title.
	 */
	private final JLabel titleLabel;
	/**
	 * slider.
	 */
	private final JSlider slider;
	/**
	 * label value.
	 */
	private final JLabel valueLabel;

	/**
	 * Build the Sliderpanel with a title.
	 * @param  title title
	 */
	public SliderPanel(final String title) {
		setLayout(new BorderLayout());
		setSize(0, 30);
		// add the title
		titleLabel = new JLabel(title);
		add(titleLabel, BorderLayout.NORTH);

		// add the slider
		slider = new JSlider();
		slider.setValue(0);
		add(slider, BorderLayout.CENTER);

		// add the label value
		valueLabel = new JLabel("0");
		add(valueLabel, BorderLayout.EAST);

		// add the listener
		SliderPanelListener sliderPanelListener = new SliderPanelListener(
				valueLabel);
		slider.addMouseListener(sliderPanelListener);
		slider.addChangeListener(sliderPanelListener);
	}

	/**
	 * to change the value
	 * 
	 * @param value
	 */
	public void setValue(final int value) {
		slider.setValue(value);
	}

	public int getValue() {
		return slider.getValue();
	}

	public void setMinimum(final int minimum) {
		slider.setMinimum(minimum);
	}

	public void setMaximum(final int maximum) {
		slider.setMaximum(maximum);
	}
}